package com.atguigu.config;

import com.atguigu.interceptor.MyInterceptor;
import com.atguigu.interceptor.MyInterceptor1;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @版本： V5.1.0
 * @版权： Copyright @ 2025 广东广昱信息科技有限公司版权所有
 * @作者： 广东广昱信息科技有限公司
 * @日期： 2025-07-04 16:04
 */
@Configuration
@ComponentScan({"com.atguigu.controller","com.atguigu.error"})
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

    //handlerMapping handlerAdapter json转换器

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/",".jsp");

        //handler -> index
    }

    //开启静态资源查找
    //dispatchServlet -> handlerMapping找有没有对应的handler -> 没有 -> 找有没有静态资源
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置方案1：拦截全部请求
        //registry.addInterceptor(new MyInterceptor());
        //配置方案2：指定地址拦截
        //*任意一层字符串 **任意多层字符串
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/user/**");
        //配置方案3：排除拦截 排除的地址应该拦截地址内部！
//        registry.addInterceptor(new MyInterceptor())
//                .excludePathPatterns("/user/**")
//                .excludePathPatterns("/user/dta");

        registry.addInterceptor(new MyInterceptor());
        registry.addInterceptor(new MyInterceptor1());
    }
}
